/*
 * TCSS 360 - Winter 2014
 * TESK Software
 */
package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;

import view.Papers.AssignReviewerstoPapersView;

import java.awt.Color;
import java.awt.Font;

/**
 * Allows a sub chair to select a conference to work with.
 * 
 * @author Emily
 * @version March 19, 2014
 */
public class SelectConferenceSubChair extends JPanel {
	
	/** The frame associated with the panel. */
	private MainFrame my_frame;
	
	/** The panel that was previously associated with the frame. */
	private JPanel my_panel;
	
	/**
	 * Constructs the panel to select a conference for the sub chair.
	 * 
	 * @param the_frame the frame the panel should be associated with
	 * @param the_panel the panel the frame was associated with previously
	 */
	public SelectConferenceSubChair(MainFrame the_frame, JPanel the_panel) {
		setBackground(new Color(245, 255, 250));
		setLayout(null);
		
		my_frame = the_frame;
		my_panel = the_panel;
		
		JPanel base = new JPanel();
		base.setBackground(new Color(240, 255, 255));
		base.setBounds(0, 0, 500, 500);
		add(base);
		base.setLayout(null);
		
		JLabel lblSelectAConference = new JLabel("Select a Conference: ");
		lblSelectAConference.setBounds(29, 133, 212, 31);
		base.add(lblSelectAConference);
		lblSelectAConference.setFont(new Font("Urdu Typesetting", Font.PLAIN, 18));
		lblSelectAConference.setForeground(new Color(138, 43, 226));
		lblSelectAConference.setBackground(new Color(255, 255, 255));
		
		
		
		ArrayList<String> conferenceList = my_frame.db.getConferences();
		final String[] conferenceArray = new String[conferenceList.size() + 1];
		conferenceArray[0] = null;
		for (int i = 0; i < conferenceList.size(); i++) {
			conferenceArray[i + 1] = conferenceList.get(i);
		}
		
		final JComboBox conferenceComboBox = new JComboBox();
		conferenceComboBox.setBackground(new Color(240, 255, 255));
		conferenceComboBox.setBounds(268, 135, 170, 28);
		base.add(conferenceComboBox);
		conferenceComboBox.setFont(new Font("Tahoma", Font.PLAIN, 18));
		conferenceComboBox.setModel(new DefaultComboBoxModel(conferenceArray));
		
		JButton continueButton = new JButton("Continue");
		continueButton.setBounds(288, 205, 108, 27);
		base.add(continueButton);
		continueButton.setFont(new Font("Tahoma", Font.PLAIN, 15));
		continueButton.setForeground(new Color(0, 0, 255));
		
		JButton cancelButton = new JButton("Cancel");
		cancelButton.setBounds(158, 205, 108, 27);
		base.add(cancelButton);
		cancelButton.setFont(new Font("Tahoma", Font.PLAIN, 15));
		cancelButton.setForeground(new Color(0, 0, 255));
		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				my_frame.setNewPanel(my_panel);
				my_frame.revalidate();
				my_frame.repaint();
			}
		});
		continueButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ((String)conferenceComboBox.getSelectedItem() != null) {
					my_frame.setNewPanel(new AssignReviewerstoPapersView(my_frame, (String)conferenceComboBox.getSelectedItem()));
				} else {
					JOptionPane.showMessageDialog(my_frame, "Please select a conference.", "Error!", JOptionPane.PLAIN_MESSAGE);
				}
			}
		});
		
		JLabel lblChooseTheConference = new JLabel("Choose a conference you want to view and edit,");
		lblChooseTheConference.setFont(new Font("Tahoma", Font.ITALIC, 14));
		lblChooseTheConference.setBounds(23, 11, 426, 37);
		base.add(lblChooseTheConference);
		
		JLabel lblAndEditYour = new JLabel(" then click Continue or go back to your main page.");
		lblAndEditYour.setFont(new Font("Tahoma", Font.ITALIC, 14));
		lblAndEditYour.setBounds(23, 46, 357, 37);
		base.add(lblAndEditYour);
		
		ImageIcon icon = new ImageIcon(getClass().getResource("/tree.jpg"));
		
		  final JLabel pic = new JLabel();
			pic.setBounds(0, 300, 500, 200);
			base.add(pic);
			pic.setIcon(icon);
			
	}

}
